<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/* 
<span class='line'>  2</span>  * Timemap.js Copyright 2010 Nick Rabinowitz.
<span class='line'>  3</span>  * Licensed under the MIT License (see LICENSE.txt)
<span class='line'>  4</span>  */</span><span class="WHIT">
<span class='line'>  5</span> 
<span class='line'>  6</span> </span><span class="COMM">/**
<span class='line'>  7</span>  * @fileOverview
<span class='line'>  8</span>  * Google Spreadsheet Loader
<span class='line'>  9</span>  *
<span class='line'> 10</span>  * @author Nick Rabinowitz (www.nickrabinowitz.com)
<span class='line'> 11</span>  */</span><span class="WHIT">
<span class='line'> 12</span> 
<span class='line'> 13</span> </span><span class="COMM">// for JSLint</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="COMM">/*global TimeMap, TimeMapItem */</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 16</span> </span><span class="COMM">/**
<span class='line'> 17</span>  * @class
<span class='line'> 18</span>  * Google Spreadsheet loader.
<span class='line'> 19</span>  *
<span class='line'> 20</span>  * &lt;p>This is a loader for data from Google Spreadsheets. The constructor takes an optional map
<span class='line'> 21</span>  * to indicate which columns contain which data elements; the default column
<span class='line'> 22</span>  * names (case-insensitive) are: title, description, start, end, lat, lon&lt;/p>
<span class='line'> 23</span>  * 
<span class='line'> 24</span>  * &lt;p>See &lt;a href="http://code.google.com/apis/spreadsheets/docs/2.0/reference.html#gsx_reference">http://code.google.com/apis/spreadsheets/docs/2.0/reference.html#gsx_reference&lt;/a>
<span class='line'> 25</span>  * for details on how spreadsheet column ids are derived. Note that date fields 
<span class='line'> 26</span>  * must be in yyyy-mm-dd format - you may need to set the cell format as "plain text" 
<span class='line'> 27</span>  * in the spreadsheet (Google's automatic date formatting won't work).&lt;/p>
<span class='line'> 28</span>  *
<span class='line'> 29</span>  * &lt;p>The loader takes either a full URL, minus the JSONP callback function, or 
<span class='line'> 30</span>  * just the spreadsheet key. Note that the spreadsheet must be published.&lt;/p>
<span class='line'> 31</span>  *
<span class='line'> 32</span>  * @augments TimeMap.loaders.jsonp
<span class='line'> 33</span>  * @requires param.js
<span class='line'> 34</span>  * @requires loaders/json.js
<span class='line'> 35</span>  *
<span class='line'> 36</span>  * @example
<span class='line'> 37</span> TimeMap.init({
<span class='line'> 38</span>     datasets: [
<span class='line'> 39</span>         {
<span class='line'> 40</span>             title: "Google Spreadsheet by key",
<span class='line'> 41</span>             type: "gss",
<span class='line'> 42</span>             options: {
<span class='line'> 43</span>                 key: "pjUcDAp-oNIOjmx3LCxT4XA" // Spreadsheet key
<span class='line'> 44</span>             }
<span class='line'> 45</span>         },
<span class='line'> 46</span>         {
<span class='line'> 47</span>             title: "Google Spreadsheet by url",
<span class='line'> 48</span>             type: "gss",
<span class='line'> 49</span>             options: {
<span class='line'> 50</span>                 url: "http://spreadsheets.google.com/feeds/list/pjUcDAp-oNIOjmx3LCxT4XA/1/public/values?alt=json-in-script&callback="
<span class='line'> 51</span>             }
<span class='line'> 52</span>         }
<span class='line'> 53</span>     ],
<span class='line'> 54</span>     // etc...
<span class='line'> 55</span> });
<span class='line'> 56</span>  * @see &lt;a href="../../examples/google_spreadsheet.html">Google Spreadsheet Example&lt;/a>
<span class='line'> 57</span>  * @see &lt;a href="../../examples/google_spreadsheet_columns.html">Google Spreadsheet Example, Arbitrary Columns&lt;/a>
<span class='line'> 58</span>  *
<span class='line'> 59</span>  * @param {Object} options          All options for the loader:
<span class='line'> 60</span>  * @param {String} options.key                      Key of spreadsheet to load, or
<span class='line'> 61</span>  * @param {String} options.url                      Full JSONP url of spreadsheet to load
<span class='line'> 62</span>  * @param {Object} [options.paramMap]               Map of paramName:columnName pairs for core parameters, 
<span class='line'> 63</span>  *                                                  if using non-standard column names; see keys in 
<span class='line'> 64</span> *                                                   {@link TimeMap.loaders.base#params} for the standard param names
<span class='line'> 65</span>  * @param {String[]} [options.extraColumns]         Array of additional columns to load; all named columns will be 
<span class='line'> 66</span>  *                                                  loaded into the item.opts object.
<span class='line'> 67</span>  * @param {mixed} [options[...]]    Other options (see {@link TimeMap.loaders.jsonp})
<span class='line'> 68</span>  */</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="NAME">TimeMap.loaders.gss</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">loader</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">TimeMap.loaders.jsonp</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">        </span><span class="NAME">params</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">loader.params</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">paramName</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">        </span><span class="NAME">setParamField</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">TimeMap.loaders.gss.setParamField</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">        </span><span class="NAME">paramMap</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.paramMap</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">        </span><span class="NAME">extraColumns</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.extraColumns</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">    </span><span class="COMM">// use key if no URL was supplied</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">loader.opts.url</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">options.key</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">        </span><span class="NAME">loader.opts.url</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">"http://spreadsheets.google.com/feeds/list/"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">            </span><span class="NAME">options.key</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"/1/public/values?alt=json-in-script&callback=?"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">    
<span class='line'> 82</span>     </span><span class="COMM">// Set up additional columns</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">=</span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">extraColumns.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">        </span><span class="NAME">paramName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">extraColumns</span><span class="PUNC">[</span><span class="NAME">x</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">        </span><span class="NAME">params</span><span class="PUNC">[</span><span class="NAME">paramName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">TimeMap.params.OptionParam</span><span class="PUNC">(</span><span class="NAME">paramName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">    
<span class='line'> 88</span>     </span><span class="COMM">// Set up parameters to work with Google Spreadsheets</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">paramName</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">params</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">params.hasOwnProperty</span><span class="PUNC">(</span><span class="NAME">paramName</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">            </span><span class="NAME">fieldName</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">paramMap</span><span class="PUNC">[</span><span class="NAME">paramName</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">paramName</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">            </span><span class="NAME">setParamField</span><span class="PUNC">(</span><span class="NAME">params</span><span class="PUNC">[</span><span class="NAME">paramName</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fieldName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">    
<span class='line'> 96</span>     </span><span class="COMM">/**
<span class='line'> 97</span>      * Preload function for spreadsheet data
<span class='line'> 98</span>      * @name TimeMap.loaders.gss#preload
<span class='line'> 99</span>      * @function
<span class='line'>100</span>      * @parameter {Object} data     Data to preload
<span class='line'>101</span>      * @return {Array} data         Array of item data
<span class='line'>102</span>      */</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">    </span><span class="NAME">loader.preload</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">data.feed.entry</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">    
<span class='line'>107</span>     </span><span class="COMM">/**
<span class='line'>108</span>      * Transform function for spreadsheet data
<span class='line'>109</span>      * @name TimeMap.loaders.gss#transform
<span class='line'>110</span>      * @function
<span class='line'>111</span>      * @parameter {Object} data     Data to transform
<span class='line'>112</span>      * @return {Object} data        Transformed data for one item
<span class='line'>113</span>      */</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT">    </span><span class="NAME">loader.transform</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">item</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">params</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">loader.params</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">paramName</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">            </span><span class="NAME">transform</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.transformFunction</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">        </span><span class="COMM">// run through parameters, loading each</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">        </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">paramName</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">params</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">params.hasOwnProperty</span><span class="PUNC">(</span><span class="NAME">paramName</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">                </span><span class="NAME">params</span><span class="PUNC">[</span><span class="NAME">paramName</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">setConfigGSS</span><span class="PUNC">(</span><span class="NAME">item</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">        </span><span class="COMM">// hook for further transformation</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">        </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">transform</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">            </span><span class="NAME">item</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">transform</span><span class="PUNC">(</span><span class="NAME">item</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">item</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> 
<span class='line'>130</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">loader</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>131</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>132</span> 
<span class='line'>133</span> </span><span class="COMM">/**
<span class='line'>134</span>  * Set a parameter to get its value from a given Google Spreadsheet field.
<span class='line'>135</span>  *
<span class='line'>136</span>  * @param {TimeMap.Param} param     Param object
<span class='line'>137</span>  * @param {String} fieldName        Name of the field
<span class='line'>138</span>  */</span><span class="WHIT">
<span class='line'>139</span> </span><span class="NAME">TimeMap.loaders.gss.setParamField</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">param</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fieldName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">    </span><span class="COMM">// internal function: Get the value of a Google Spreadsheet field</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">getField</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fieldName</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">        </span><span class="COMM">// get element, converting field name to GSS format</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">el</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="STRN">'gsx$'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">fieldName.toLowerCase</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">" "</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">        </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">el</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">el.$t</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">    </span><span class="COMM">// set the method on the parameter</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">    </span><span class="NAME">param.setConfigGSS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">config</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">        </span><span class="NAME">this.setConfig</span><span class="PUNC">(</span><span class="NAME">config</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">getField</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fieldName</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>150</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>151</span> </span></pre></body></html>